﻿using Microsoft.AspNet.Identity;
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Helpers;
using DoMain.IdentityRoles;
using DoMain.IdentityUsers;
using DoMain.IdentityUserRoles;

namespace WebMvc.Models
{
    public class MyRoleStore : IRoleStore<IdentityRole> 
    {
        private IIdentityRoleRepository _roleRepo;
        private IIdentityUserRepository _userRepo;
        private IIdentityUserRoleRepository _userRolesRepo;
        public MyRoleStore(IIdentityUserRepository userRepo, IIdentityRoleRepository roleRepo,IIdentityUserRoleRepository userRoleRepo) {
            _userRepo = userRepo;
            _roleRepo = roleRepo;
            _userRolesRepo = userRoleRepo;
        }

        public IQueryable<IdentityRole> Roles
        {
            get
            {
                return _roleRepo.FindAll().AsQueryable();
            }
        }

        public Task CreateAsync(IdentityRole role)
        {
            return _roleRepo.InsertAsync(role);
        }

        public Task DeleteAsync(IdentityRole role)
        {
            return _roleRepo.DeleteAsync(role);
        }

        public void Dispose()
        {
            
            
        }

        public Task<IdentityRole> FindByIdAsync(string roleId)
        {
            return _roleRepo.FindByIdAsync(roleId);
             
        }

        public Task<IdentityRole> FindByNameAsync(string roleName)
        {
            return _roleRepo.FindAsync(s=>s.Name==roleName);
            throw new NotImplementedException();
        }

        public Task UpdateAsync(IdentityRole role)
        {
            return _roleRepo.UpdateAsync(role);
            throw new NotImplementedException();
        }
    }
}
